﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace GeoSwarm_Editor
{
    public partial class StatusDialog : Form
    {

        private bool closingProg = false;
        private Form parent;

        public StatusDialog(Form parent, string title, string statusText)
        {
            InitializeComponent();
            this.Text = title;
            statusLabel.Text = statusText;
            progressBar.Style = ProgressBarStyle.Marquee;
            this.parent = parent;
        }

        public StatusDialog(Form parent, string title, string statusText, int percentDone)
        {
            InitializeComponent();
            this.Text = title;
            statusLabel.Text = statusText;
            progressBar.Value = percentDone;
            progressBar.Style = ProgressBarStyle.Continuous;
            this.parent = parent;
        }

        private delegate void UpdatePercentDoneCallback(int percentDone);

        public void UpdatePercentDone(int percentDone)
        {
            if (this.InvokeRequired)
            {
                UpdatePercentDoneCallback d = new UpdatePercentDoneCallback(UpdatePercentDone);
                this.Invoke(d, percentDone);
            }
            else
            {
                progressBar.Style = ProgressBarStyle.Continuous;
                progressBar.Value = percentDone;
            }
        }

        public void UpdateStatus(string status)
        {
            statusLabel.Text = status;
        }

        public void Update(string status, int percentDone)
        {
            progressBar.Style = ProgressBarStyle.Continuous;
            progressBar.Value = percentDone;
            statusLabel.Text = status;
        }

        public void CloseProg()
        {
            this.closingProg = true;
            this.Close();
        }

        private void StatusDialog_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (this.closingProg)
            {
                this.parent.Enabled = true;
                this.Hide();
            }
            e.Cancel = true;
        }

        private void StatusDialog_Shown(object sender, EventArgs e)
        {
            this.parent.Enabled = false;
        }

        #region Properties

        public int ProgPercent
        {
            get
            {
                return progressBar.Value;
            }
        }

        public ProgressBarStyle ProgBarStyle
        {
            get
            {
                return progressBar.Style;
            }
            set
            {
                progressBar.Style = value;
            }
        }

        public string DialogTitle
        {
            get
            {
                return this.Text;
            }
            set
            {
                this.Text = value;
            }
        }

        #endregion
    }
}
